package cuongnh.project.japanesediary.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "tbl_radical")
public class Radical extends AbstractModelObject {

	@Id
	@Column(name = "radical_id")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="radical_seq")
	@SequenceGenerator(
			name="radical_seq",
			sequenceName="radical_sequence",
			allocationSize=1
		)
	private Long radicalId;

	@Column(name = "radical", length = 1)
	private String radical;
	
	@Column(name = "furigana", length = 10)
	private String furigana;
	
	@Column(name = "meaning_vietnamese", length = 20)
	private String vnMeaning;

	@Column(name = "meaning_english", length = 20)
	private String enMeaning;

	@Column(name = "meaning_japanese", length = 20)
	private String jpMeaning;

	@Column(name = "explaination_vietnamese", length = 100)
	private String vnExplaination;

	@Column(name = "explaination_english", length = 100)
	private String enExplaination;

	@Column(name = "explaination_japanese", length = 100)
	private String jpExplaination;
	
	@ManyToMany(mappedBy="radicals", fetch = FetchType.LAZY)
	private Set<Kanji> kanjis = new HashSet<Kanji>();

	public long getRadicalId() {
		return radicalId;
	}

	public void setRadicalId(long radicalId) {
		this.radicalId = radicalId;
	}

	public String getRadical() {
		return radical;
	}

	public void setRadical(String radical) {
		this.radical = radical;
	}
	
	public String getFurigana() {
		return furigana;
	}

	public void setFurigana(String furigana) {
		this.furigana = furigana;
	}

	public String getVnMeaning() {
		return vnMeaning;
	}

	public void setVnMeaning(String vnMeaning) {
		this.vnMeaning = vnMeaning;
	}

	public String getEnMeaning() {
		return enMeaning;
	}

	public void setEnMeaning(String enMeaning) {
		this.enMeaning = enMeaning;
	}

	public String getJpMeaning() {
		return jpMeaning;
	}

	public void setJpMeaning(String jpMeaning) {
		this.jpMeaning = jpMeaning;
	}

	public String getVnExplaination() {
		return vnExplaination;
	}

	public void setVnExplaination(String vnExplaination) {
		this.vnExplaination = vnExplaination;
	}

	public String getEnExplaination() {
		return enExplaination;
	}

	public void setEnExplaination(String enExplaination) {
		this.enExplaination = enExplaination;
	}

	public String getJpExplaination() {
		return jpExplaination;
	}

	public void setJpExplaination(String jpExplaination) {
		this.jpExplaination = jpExplaination;
	}

	public Set<Kanji> getKanjis() {
		return kanjis;
	}

	public void setKanjis(Set<Kanji> kanjis) {
		Set<Kanji> oldValue = this.kanjis;
		this.kanjis = kanjis;
		firePropertyChange("kanjis", oldValue, kanjis);
	}
	
	@Override
	public boolean equals(Object obj) {
		boolean sameSame = false;

		if (obj != null && obj instanceof Radical) {
			sameSame = radicalId.equals(((Radical) obj).radicalId);
		}

		return sameSame;
	}
	
	@Override
	public int hashCode() {
		return this.radicalId.intValue();
	}
}
